package com.example.common.service.impl;

import com.example.common.mapper.IDataLogMapper;
import com.example.common.mapper.IWorkShopMapper;
import com.example.common.pojo.*;
import com.example.common.service.ICompCompensateService;
import com.example.right.service.IRightService;
import com.example.util.Constants;
import org.springframework.stereotype.Service;

@Service
public class ICompCompensateServiceImpl implements ICompCompensateService {
    private IWorkShopMapper iWorkShopMapper;
    private IRightService iRightService;
    private IDataLogMapper iDataLogMapper;
    public ICompCompensateServiceImpl(IWorkShopMapper iWorkShopMapper,IRightService iRightService,IDataLogMapper iDataLogMapper){
        this.iWorkShopMapper=iWorkShopMapper;
        this.iDataLogMapper=iDataLogMapper;
        this.iRightService=iRightService;
    }

    @Override
    public int insertOfficeRoom(int id, OfficeRoom officeRoom) {
        if(!this.iRightService.checkPermission(id,Constants.INSERT)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.INSERT,id,officeRoom.toString());
        return this.iWorkShopMapper.insertOffice(officeRoom.getOfficePrice(),
                officeRoom.getOfficeAmount(),
                officeRoom.getOfficeSqmeter(),
                officeRoom.getOfficeLevel(),
                id);
        //return this.iDataLogMapper.insertDataLog(Constants.INSERT,id,officeRoom.toString());
    }

    @Override
    public int insertWorkShop(int id,WorkShop workShop) {
        if(!this.iRightService.checkPermission(id,Constants.INSERT)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.INSERT,id,workShop.toString());
        return this.iWorkShopMapper.insertWorkShop(workShop.getWorkshopAmount(),
                workShop.getWorkshopSqmeter(),workShop.getWorkshopLevel(),
                workShop.getWorkshopPrice(), id);
        //return this.iDataLogMapper.insertDataLog(Constants.INSERT,id,workShop.toString());

    }

    @Override
    public int insertBrickFloor(int id, BrickFloor brickFloor) {
        if(!this.iRightService.checkPermission(id,Constants.INSERT)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.INSERT,id,brickFloor.toString());
        return this.iWorkShopMapper.insertBrickFloor(
                brickFloor.getBrickPrice(),brickFloor.getBrickAmount(),
                brickFloor.getBrickSqmeter(),id
        );
       // return this.iDataLogMapper.insertDataLog(Constants.INSERT,id,brickFloor.toString());
    }

    @Override
    public int insertSmallRoom(int id, SmallRoom smallRoom) {
        if(!this.iRightService.checkPermission(id,Constants.INSERT)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.INSERT,id,smallRoom.toString());
        return this.iWorkShopMapper.insertSmallRoom(smallRoom.getRoomPrice(),
                smallRoom.getRoomAmount(),smallRoom.getRoomSqmeter(),id);
   // return this.iDataLogMapper.insertDataLog(Constants.INSERT,id,smallRoom.toString());
    }

    @Override
    public int insertEnclosingWall(int id, EnclosingWal enclosingWal) {
        if(!this.iRightService.checkPermission(id,Constants.INSERT)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.INSERT,id,enclosingWal.toString());
        return this.iWorkShopMapper.insertEnclosingWall(enclosingWal.getEnclosingPrice(),
                enclosingWal.getEnclosingAmount(),
                enclosingWal.getEnclosingSqmeter(),id);
    //    return this.iDataLogMapper.insertDataLog(Constants.INSERT,id,enclosingWal.toString());
    }

    @Override
    public int insertRetainintWall(int id, RetainWall retainWall) {
        if(!this.iRightService.checkPermission(id,Constants.INSERT)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.INSERT,id,retainWall.toString());
        return this.iWorkShopMapper.inseretRetainingWall(
                retainWall.getRetainingPrice(),retainWall.getRetainingAmount(),
                retainWall.getRetainingSqmeter(),id
        );
       // return this.iDataLogMapper.insertDataLog(Constants.INSERT,id,retainWall.toString());
    }

    @Override
    public int insertCementRoad(int id, CementRoad cementRoad) {
        if(!this.iRightService.checkPermission(id,Constants.INSERT)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.INSERT,id,cementRoad.toString());
        return this.iWorkShopMapper.insertCementRoad(
                cementRoad.getCementroadPrice(),
                cementRoad.getCementroadAmount(),
                cementRoad.getCementroadSqmeter(),
                id
        );
        //return this.iDataLogMapper.insertDataLog(Constants.INSERT,id,cementRoad.toString());

    }
    @Override
    public int insertCementFloor(int id, CementFloor cementFloor) {
        if(!this.iRightService.checkPermission(id,Constants.INSERT)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.INSERT,id,cementFloor.toString());
        return this.iWorkShopMapper.insertCementFloor(cementFloor.getCementfloorPrice(),
                cementFloor.getCementfloorAmount(),
                cementFloor.getCementfloorSqmeter(),
                id
        );

       // return this.iDataLogMapper.insertDataLog(Constants.INSERT,id,cementFloor.toString());
    }

    @Override
    public int insertAsphaltRoad(int id, AsphaltRoad asphaltRoad) {
        if(!this.iRightService.checkPermission(id,Constants.INSERT)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.INSERT,id,asphaltRoad.toString());
        return this.iWorkShopMapper.insertAsphaltRoad(asphaltRoad.getAsphaltroadPrice(),
                asphaltRoad.getAsphaltroadAmount(),
                asphaltRoad.getAsphaltroadSqmeter(),id);

    //    return this.iDataLogMapper.insertDataLog(Constants.INSERT,id,asphaltRoad.toString());
    }

    @Override
    public int insertSlopeProtectionWall(int id, SlopeProWall slopeProWall) {
        if(!this.iRightService.checkPermission(id,Constants.INSERT)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.INSERT,id,slopeProWall.toString());
        return this.iWorkShopMapper.insertSlopeProtectionWall(
                slopeProWall.getSlopePrice(),
                slopeProWall.getSlopeAmount(),
                slopeProWall.getSlopeSqmeter(),
                id
        );

       // return this.iDataLogMapper.insertDataLog(Constants.INSERT,id,slopeProWall.toString());
    }

    @Override
    public WorkShop getWorkShop(int id) {
        return this.iWorkShopMapper.getWorkShop(id);
    }

    @Override
    public OfficeRoom getOfficeRoom(int id) {
        return this.iWorkShopMapper.getOfficeRoom(id);
    }

    @Override
    public BrickFloor getBrickFloor(int id) {
        return this.iWorkShopMapper.getBrickFloor(id);
    }

    @Override
    public SmallRoom getSmallRoom(int id) {
        return this.iWorkShopMapper.getSmallRoom(id);
    }

    @Override
    public EnclosingWal getEnclosingWall(int id) {
        return this.iWorkShopMapper.getEnclosingWall(id);
    }

    @Override
    public RetainWall getRetainingWall(int id) {
        return this.iWorkShopMapper.getRetainingWall(id);
    }

    @Override
    public CementRoad getCementRoad(int id) {
        return this.iWorkShopMapper.getCementRoad(id);
    }

    @Override
    public CementFloor getCementFloor(int id) {
        return this.iWorkShopMapper.getCementFloor(id);
    }

    @Override
    public AsphaltRoad getAsphaltRoad(int id) {
        return this.iWorkShopMapper.getAsphaltRoad(id);
    }

    @Override
    public SlopeProWall getSlopeProWall(int id) {
        return this.iWorkShopMapper.getSlopeproWall(id);
    }

    @Override
    public int updateWorkShop(int id, WorkShop workShop) {
        if(!this.iRightService.checkPermission(id,Constants.UPDATE)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,workShop.toString());
        return this.iWorkShopMapper.updateWorkShop(workShop.getWorkshopAmount(),workShop.getWorkshopSqmeter(),
                workShop.getWorkshopLevel(),workShop.getWorkshopPrice(),id);

   //     return this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,workShop.toString());
    }

    @Override
    public int updateOfficeRoom(int id, OfficeRoom officeRoom) {
        if(!this.iRightService.checkPermission(id,Constants.UPDATE)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,officeRoom.toString());
        return this.iWorkShopMapper.updateOfficeRoom(officeRoom.getOfficePrice(),officeRoom.getOfficeAmount(),officeRoom.getOfficeSqmeter(),
                officeRoom.getOfficeLevel(),id);

    //    return this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,officeRoom.toString());
    }

    @Override
    public int updateBrickFloor(int id, BrickFloor brickFloor) {
        if(!this.iRightService.checkPermission(id,Constants.UPDATE)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,brickFloor.toString());
        return this.iWorkShopMapper.updateBrickFloor(brickFloor.getBrickPrice(),brickFloor.getBrickAmount(),brickFloor.getBrickSqmeter(),id);
//        return this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,brickFloor.toString());
    }

    @Override
    public int updateSmallRoom(int id, SmallRoom smallRoom) {
        if(!this.iRightService.checkPermission(id,Constants.UPDATE)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,smallRoom.toString());
        return this.iWorkShopMapper.updateSmallRoom(smallRoom.getRoomPrice(),smallRoom.getRoomAmount(),smallRoom.getRoomSqmeter(),id);
//        return this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,smallRoom.toString());
    }

    @Override
    public int updateEnclosingWall(int id, EnclosingWal enclosingWal) {
        if(!this.iRightService.checkPermission(id,Constants.UPDATE)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,enclosingWal.toString());
        return this.iWorkShopMapper.updateEnclosingWall(enclosingWal.getEnclosingPrice(),
                enclosingWal.getEnclosingAmount(),
                enclosingWal.getEnclosingSqmeter(),
                id);

//        return this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,enclosingWal.toString());
    }

    @Override
    public int updateRetainingWall(int id, RetainWall retainWall) {
        if(!this.iRightService.checkPermission(id,Constants.UPDATE)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,retainWall.toString());
        return this.iWorkShopMapper.updateRetainingWall(retainWall.getRetainingPrice(),retainWall.getRetainingAmount(),retainWall.getRetainingSqmeter(),id);
//        return this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,retainWall.toString());
    }

    @Override
    public int updateCementRoad(int id, CementRoad cementRoad) {
        if(!this.iRightService.checkPermission(id,Constants.UPDATE)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,cementRoad.toString());
        return this.iWorkShopMapper.updateCementRoad(cementRoad.getCementroadPrice(),cementRoad.getCementroadAmount(),cementRoad.getCementroadSqmeter(),id);
//        return this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,cementRoad.toString());
    }

    @Override
    public int updateCementFloor(int id, CementFloor cementFloor) {
        if(!this.iRightService.checkPermission(id,Constants.UPDATE)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,cementFloor.toString());
        return this.iWorkShopMapper.updateCementFloor(cementFloor.getCementfloorPrice(),cementFloor.getCementfloorAmount(),cementFloor.getCementfloorSqmeter(),id);
//        return this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,cementFloor.toString());
    }

    @Override
    public int updateAsphaltRoad(int id, AsphaltRoad asphaltRoad) {
        if(!this.iRightService.checkPermission(id,Constants.UPDATE)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,asphaltRoad.toString());
        return this.iWorkShopMapper.updateAsphaltRoad(asphaltRoad.getAsphaltroadPrice(),asphaltRoad.getAsphaltroadAmount(),asphaltRoad.getAsphaltroadSqmeter(),id);
//        return this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,asphaltRoad.toString());
    }

    @Override
    public int updateSlopeProWall(int id, SlopeProWall slopeProWall) {
        if(!this.iRightService.checkPermission(id,Constants.UPDATE)){
            return Constants.NO_PERMISSION;
        }
        this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,slopeProWall.toString());
        return this.iWorkShopMapper.updateSlopeProWall(slopeProWall.getSlopePrice(),slopeProWall.getSlopeAmount(),slopeProWall.getSlopeSqmeter(),id);
//        return this.iDataLogMapper.insertDataLog(Constants.UPDATE,id,slopeProWall.toString());
    }
}
